﻿using System;
using Netkk.Common;
using Netkk.Common.Models;

namespace Netkk.Models
{
    public class NewsModel
    {
        public Guid Id { get; set; }
        public string Title { get; set; }
        public string Teaser { get; set; }
        public string Text { get; set; }
        public DateTime Date { get; set; }
        public string CleanTitle { get; set; }
        public bool ShowEditNews { get; set; }

        public static NewsModel Create()
        {
            return new NewsModel
                       {
                           Id = Guid.NewGuid(),
                           Title = String.Empty,
                           Teaser = String.Empty,
                           Text = String.Empty,
                           Date = DateTime.Now
                       };
        }
        public static NewsModel Create(News news)
        {
            return new NewsModel
                        {
                            CleanTitle = Tools.GetCleanUrl(news.Title),
                            Title = news.Title,
                            Teaser = news.Teaser,
                            Text = news.Text,
                            Date = news.Date,
                            Id = news.Id
                        };
        }
        public static NewsModel Create(News news, bool allowEdit)
        {
            return new NewsModel
                       {
                           CleanTitle = Tools.GetCleanUrl(news.Title),
                           Title = news.Title,
                           Teaser = news.Teaser,
                           Text = news.Text,
                           Date = news.Date,
                           Id = news.Id,
                           ShowEditNews = allowEdit
                       };
        }

        public News MapNews()
        {
            return new News
               {
                   Id = Id,
                   Title = Title,
                   Date = Date,
                   Teaser = Teaser,
                   Text = Text
               };
        }

        public News MapNews(Guid id)
        {
            return new News
            {
                Id = id,
                Title = Title,
                Date = Date,
                Teaser = Teaser,
                Text = Text
            };
        }
    }
}
